/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package batailledesardennes.util.geomFloat.path;

import batailledesardennes.util.FastMath;
import batailledesardennes.util.geomFloat.Point;
import java.util.ArrayList;
import java.util.List;

/**
 *
 * @author cghislai
 */
public class Node implements Comparable<Node> {

    public static enum PathStatus {

        OPEN, CLOSED;
    }
    private final Point point;
    private final List<Node> connectedNodes;
    private Obstacle obstacle;
    // Pathfinding
    private Node parent;
    private float fCost;
    private float gCost;
    private float hCost;
    private final List<Node> tempNodes;
    private PathStatus pathStatus;

    public Node() {
        point = new Point();
        connectedNodes = new ArrayList<Node>();
        tempNodes = new ArrayList<Node>();
        parent = null;
    }

    public Node(Point point) {
        this.point = point;
        connectedNodes = new ArrayList<Node>();
        tempNodes = new ArrayList<Node>();
        parent = null;
    }

    public void setParent(Node parent) {
        this.parent = parent;
    }

    public void clearConnectedNodes() {
        for (Node node : connectedNodes) {
            node.connectedNodes.remove(this);
        }
        connectedNodes.clear();
    }

    public void clearTempNodes() {
        for (Node node : tempNodes) {
            node.tempNodes.remove(this);
        }
        tempNodes.clear();
    }

    public void calcHCost(Node target) {
        hCost = point.distance(target.getPoint());
    }

    public void calcFCost() {
        fCost = gCost + hCost;
    }

    @Override
    public int compareTo(Node t) {
        return (int) FastMath.ceil(fCost - t.fCost);
    }

    public List<Node> getConnectedNodes() {
        return connectedNodes;
    }

    public List<Node> getTempNodes() {
        return tempNodes;
    }

    public float getfCost() {
        return fCost;
    }

    public float getgCost() {
        return gCost;
    }

    public void setgCost(float gCost) {
        this.gCost = gCost;
    }

    public float gethCost() {
        return hCost;
    }

    public Node getParent() {
        return parent;
    }

    public Point getPoint() {
        return point;
    }

    public Obstacle getObstacle() {
        return obstacle;
    }

    public void setObstacle(Obstacle obstacle) {
        this.obstacle = obstacle;
    }

    public PathStatus getPathStatus() {
        return pathStatus;
    }

    public void setPathStatus(PathStatus pathStatus) {
        this.pathStatus = pathStatus;
    }
}
